<link rel="stylesheet" href="/plugin/resource/pintuer/pintuer.css">
<script src="/plugin/resource/pintuer/pintuer.js"></script>
<script src="/data/resource/layer/layer.js"></script>
<?php
$config = @include (dirname(BASE_PATH) . '/data/mobile/config.php');
if (empty($config)) {
    $config = array();
}
?>



<div class="pintuer">
    <div class=" padding-left">
        <h4 class="text-yellow">
            第一屏设置
        </h4>
    </div>

    <hr class="bg-yellow">

    <style>
        #background {
            width: 350px;
            height: 540px;
            margin: 51px 26px 79px 24px;
            border: 1px solid #000;
        }
    </style>
    <div class="margin-top margin-left"
         style="display: inline-block;width: 400px;height: 670px;background: #000;background: url(/admin/templates/default/images/mobile/mpat.png) no-repeat 0 0;">
        <div id="background">

        </div>
    </div>

    <form action='/admin/?act=mb_special&op=save_first_pic' method="post" style="display: inline-block;vertical-align: top;">
        <div class="padding-top" style="display: inline-block;vertical-align: top;">
            <label style="margin-right: 10px;">
                <input <?php if($config['open_first_pic'] == 1) echo 'checked'?> type="checkbox" name="open_first_pic" value="1">开启第一屏图片
            </label>
            <label>
                <input <?php if($config['open_icons'] == 1) echo 'checked'?> type="checkbox" name="open_icons" value="1">开启图标
            </label>

            <div style="height: 20px;">

            </div>

            <a href="javascript:;" class="button bg-yellow" id="upload_pic">上传第一屏图片</a>
            <input type="file" name="upload" style="display: none;">
            <input type="hidden" name="pic" value="<?php echo $config['pic'];?>">
            <table class="table table-bordered">
                <tr class="thead">
                    <th>
                        图标
                    </th>
                    <th>
                        文字
                    </th>
                    <th>
                        链接
                    </th>
                </tr>
                <?php
                for ($i = 0; $i < 5; $i++) {

                    ?>
                    <tr>
                        <td>
                            <input type="file" >
                            <input type="hidden" name="pics[]" value="<?php echo $config['pics'][$i]?>">
                        </td>
                        <td>
                            <input type="text" name="text[]" value="<?php echo $config['text'][$i] ?>">
                        </td>
                        <td>
                            <input type="text" name="link[]" value="<?php echo $config['link'][$i] ?>">
                        </td>
                    </tr>
                    <?php
                }
                ?>

            </table>
        </div>
    </form>


    <hr>

    <div style="clear: both;margin-left: 20px;">
        <a href="javascript:;" class="button bg-yellow margin-left" id="save">保存设置</a>
    </div>
</div>
<script>
    $('#upload_pic').click(function () {
        $('[name=upload]').click();
    });

    var this_pic = '<?php echo $config['pic'];?>';
    if (this_pic != '') {
        $('#background').css({
            background: 'url(' + this_pic + ')'
        })
    }

    $('[type=file]').change(function (e) {
        var file = this.files[0];
        var fr = new FileReader();
        var _this = $(this);
        fr.onload = function (e) {
            var result = e.target.result;
            if(_this.attr('name') == 'upload'){
                this_pic = result;
                $('#background').css({
                    background: 'url(' + result + ')'
                });
            }
            _this.next().val(result);
        }

        fr.readAsDataURL(file);
    });

    $('#save').click(function () {
        $('form').submit();
        return;
        var index = layer.load();
        $.post('/admin/?act=mb_special&op=save_first_pic', {pic: this_pic}, function (msg) {
            layer.close(index);
            if (msg == 'success') {
                layer.msg("保存成功");
            }
            else {
                layer.msg("保存失败");
            }

        })
    })


</script>